import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * User: James Barker
 * Date: 1/08/11
 */
public class ElevatorSimulatorJava extends JFrame implements ActionListener {

    //AdminUI aui;
    FloorUI fui;
    ElevatorUI eui;
    ElevatorController ec;

    public ElevatorSimulatorJava() {
        this.setLayout(new FlowLayout(1));
        this.setTitle("AdminUI");
        this.setSize(300, 300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        displayFloorUI();
    }

    public void displayFloorUI() {
        fui = new FloorUI();
        fui.callLift.addActionListener(this);
        this.add(fui);
        ec = new ElevatorController(1, 3);
    }

    public void actionPerformed(ActionEvent ae) {
        if (ae.getActionCommand().equals("call")) {
            System.out.println("CALLING");
            ec.moveElevator(fui.getCurrentFloor());
            fui.callLift.setText("enter");
        }

        if (ae.getActionCommand().equals("enter")) {
            System.out.println("ENTERING LIFT");
            fui.setVisible(false);

            eui = new ElevatorUI(ec.e.getMinFloor(), ec.e.getMaxFloor());
            eui.jb1.addActionListener(this);
            eui.jb2.addActionListener(this);
            eui.jb3.addActionListener(this);

            this.add(eui);
        }

        if (ae.getActionCommand().equals("1")) {
            System.out.println("pressed 1");
            ec.moveElevator(1);
            eui.setVisible(false);
            displayFloorUI();
        }

        if (ae.getActionCommand().equals("2")) {
            System.out.println("pressed 2");
            ec.moveElevator(2);
            eui.setVisible(false);
            displayFloorUI();
        }

        if (ae.getActionCommand().equals("3")) {
            System.out.println("pressed 3");
            ec.moveElevator(3);
            eui.setVisible(false);
            displayFloorUI();
        }
    }

    public static void main(String[] args) {
        new ElevatorSimulatorJava();
    }
}
